package com.zbec.mdrs.service;

import com.zbec.mdrs.entity.discount.Discount;
import com.zbec.mdrs.entity.drafts.Drafts;
import com.zbec.mdrs.entity.entrustedLoan.EntrustedLoan;
import com.zbec.mdrs.entity.loan.Loan;
import org.kie.api.cdi.KBase;
import org.kie.api.cdi.KSession;
import org.kie.api.runtime.KieSession;
import org.springframework.stereotype.Service;

/**
 * Created by Administrator on 2017/3/20.
 */
@Service
public class ValidationService {

    @KSession("loan_ksession")
    KieSession loankSession;

    @KSession("discount_ksession")
    KieSession discountSession;

    @KSession("drafts_ksession")
    KieSession draftsSession;

    @KSession("entrustedLoan_ksession")
    KieSession entrustedLoanSession;


    public void validLoan (Loan loan) {
        if (loan == null) {
            throw new NullPointerException("loan can not be null.");
        }

        loankSession.insert(loan);
        loankSession.fireAllRules();
    }

    public void validDiscount (Discount discount) {
        if (discount == null) {
            throw new NullPointerException("loan can not be null.");
        }

        discountSession.insert(discount);
        discountSession.fireAllRules();
    }

    public void validDrafts (Drafts drafts) {
        if (drafts == null) {
            throw new NullPointerException("loan can not be null.");
        }

        draftsSession.insert(drafts);
        draftsSession.fireAllRules();
    }

    public void validEntrustedLoan (EntrustedLoan entrustedLoan) {
        if (entrustedLoan == null) {
            throw new NullPointerException("loan can not be null.");
        }

        entrustedLoanSession.insert(entrustedLoan);
        entrustedLoanSession.fireAllRules();
    }
}
